/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.qhq.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.qhq.entity.SchoolParent;
import com.thinkgem.jeesite.modules.qhq.service.SchoolParentService;

/**
 * 学院表Controller
 * @author 秦华权
 * @version 2017-11-28
 */
@Controller
@RequestMapping(value = "${adminPath}/qhq/schoolParent")
public class SchoolParentController extends BaseController {

	@Autowired
	private SchoolParentService schoolParentService;
	
	@ModelAttribute
	public SchoolParent get(@RequestParam(required=false) String id) {
		SchoolParent entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = schoolParentService.get(id);
		}
		if (entity == null){
			entity = new SchoolParent();
		}
		return entity;
	}
	
	@RequiresPermissions("qhq:schoolParent:view")
	@RequestMapping(value = {"list", ""})
	public String list(SchoolParent schoolParent, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SchoolParent> page = schoolParentService.findPage(new Page<SchoolParent>(request, response), schoolParent); 
		model.addAttribute("page", page);
		return "modules/qhq/schoolParentList";
	}

	@RequiresPermissions("qhq:schoolParent:view")
	@RequestMapping(value = "form")
	public String form(SchoolParent schoolParent, Model model) {
		model.addAttribute("schoolParent", schoolParent);
		return "modules/qhq/schoolParentForm";
	}

	@RequiresPermissions("qhq:schoolParent:edit")
	@RequestMapping(value = "save")
	public String save(SchoolParent schoolParent, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, schoolParent)){
			return form(schoolParent, model);
		}
		schoolParentService.save(schoolParent);
		addMessage(redirectAttributes, "保存学院成功");
		return "redirect:"+Global.getAdminPath()+"/qhq/schoolParent/?repage";
	}
	
	@RequiresPermissions("qhq:schoolParent:edit")
	@RequestMapping(value = "delete")
	public String delete(SchoolParent schoolParent, RedirectAttributes redirectAttributes) {
		schoolParentService.delete(schoolParent);
		addMessage(redirectAttributes, "删除学院成功");
		return "redirect:"+Global.getAdminPath()+"/qhq/schoolParent/?repage";
	}

}